<?php
	require_once "weixin_info.php";//微信授权获取用户头像等信息
    require_once "config.php";
	require_once "WxPay.php";
	
	$WxPay = new WxPay();
	$trade_no = mt_rand(1000000000,9999999999);
	$money = 380;
	$Result = $WxPay->SubmitJsApiUnifiedOrder('吉事多', $trade_no, $money);
	$SignParam = $WxPay->signJsApiPrepayParam($Result['prepay_id']);


	if($_SERVER['REQUEST_METHOD'] == 'POST'){
		$shop['shop_name'] = $_POST['shop_name'];
		$shop['shop_tel'] = $_POST['shop_tel'];
		$shop['shop_add'] = $_POST['shop_add'];
		$shop['shop_contacts'] = $_POST['shop_contacts'];
		$shop['shop_yyzz'] = $_POST['shop_yyzz'];
		$shop['shop_move'] = $_POST['shop_move'];
		$shop['shop_wx'] = $_POST['shop_wx'];
		if(empty($shop['shop_name']) || empty($shop['shop_tel'])|| empty($shop['shop_add'])|| empty($shop['shop_contacts'])|| empty($shop['shop_yyzz'])|| empty($shop['shop_move'])|| empty($shop['shop_wx'])){
			$result['info'] = '请填写信息';
			$result['status'] = 'error';
			return $result;
		}
		$time = time();
		$order_num = $time.$_SESSION['Member_info'][0]['id'];
		$Up_sql = "Update dyspw_member set shop_name = '".$shop['shop_name']."', shop_tel = '".$shop['shop_tel']."',shop_add = '".$shop['shop_add']."',shop_contacts = '".$shop['shop_contacts']."',
		shop_yyzz = '".$shop['shop_yyzz']."',shop_move = '".$shop['shop_move']."',shop_wx = '".$shop['shop_wx']."' where id= ".$_SESSION['Member_info'][0]['id'];
		$or_sql = "INSERT INTO dyspw_order(order_name, uid, order_money, order_type ,order_status,order_time,order_num) VALUES ('商户充值', '".$_SESSION['Member_info'][0]['id']."', '".$money."','微信支付', -1, '".$time."','".$order_num."')";

		$add_memshop = mysqli_query($mysql, $Up_sql);
		$add_order = mysqli_query($mysql, $or_sql);
		if(!empty($add_order) && !empty($add_memshop)){
			$result['status'] = 'y';
			$result['order_num'] = $order_num;
			echo   json_encode($result);
			exit();
		}else{
			$result['status'] = 'n';
			$result['info'] = '表单提交失败，请重新提交';
			echo   json_encode($result);
			exit();
		}
	}
 ?>
<!doctype html>

<html>

<head>

	<meta charset="utf-8">

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

	<title>企业信息</title>

	<link rel="stylesheet" href="css/core.css">

	<script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>

	<script src="js/jquery.cookie.js" type="text/javascript"></script>

	<script src="js/layer/layer.js" type="text/javascript"></script>

<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

<body>

<section style="margin-bottom: 50px;">

	<div class="main" style="width:90%;padding-top:40px;">

		<div class="recharge-input-box">

			<label>商家名称：</label><input type="text" id="shop_name" />

		</div>

		<div class="recharge-input-box">

			<label>商家电话：</label><input type="text" id="shop_tel" />

		</div>

		<div class="recharge-input-box">

			<label>商家地址：</label><input type="text" id="shop_add" />

		</div>

		<div class="recharge-input-box">

			<label>联系人：</label><input type="text" id="shop_contacts" />

		</div>

		<div class="recharge-input-box facebtn">

			<label>营业执照：</label><button class=" face">上传</button>
			<input  type="hidden" id="shop_yyzz" value=""/>
			<img class="yyzz_img" src="" alt="" style="display:none; width:200px;">

		</div>
		<form action="update.php" target="exec_target" method="POST" enctype="multipart/form-data" style="display:none;">
			<input type="hidden" name="FilePath" value="Goods/Thumb" />
			<input class="img_file" name="face" type="file" multiple=true value="" >
			<input type="submit" id="PicSubmit"/>
		</form>

		<iframe id="exec_target" name="exec_target" style="display:none"></iframe>

		<script type="text/javascript">
			$(".face").click(function(){
				$(".img_file").click();
			})
			$(".yyzz_img").click(function(){
				$(".img_file").click();
			})
			$(".img_file").change(function(){
				$('#PicSubmit').click();
				$("#exec_target").load(function(){
					var data = $(window.frames['exec_target'].document.body).html();
					if(data != null){
						$(".facebtn").find("img").attr("src",data );
						$(".facebtn").find("img").show();
						$(".facebtn").find(".face").hide();
						$(".facebtn").find("input").attr("value",data );
					}
				});
			})

		</script>

		<div class="recharge-input-box">

			<label>手机号：</label><input type="text" id="shop_move" />

		</div>

		<div class="recharge-input-box">

			<label>微信：</label><input type="text" id="shop_wx" />

		</div>

		<div class="recharge-footer-box" style="padding-top:40px;">

			<p><label><i></i>我已阅读并同意<a href="#">服务条款</a>及<a href="#">隐私协议</a></label></p>

			<button class="recharge-btn">确&nbsp;&nbsp;&nbsp;定</button>

		</div>

	</div>

</section>

<footer style="background-color:#FFF;">
    <ul class="cl">
        <li><a href="index.php">首页</a></li>
        <li><a href="fenlei.php">分类</a></li>
        <li><a href="baishe.php">拍</a></li>
        <li><a href="https://fyhpm.fyh51.com/shangtao/mobile/index/index.html">商城</a></li>
        <li><a href="member.php">我</a></li>
    </ul>
</footer>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

<script type="text/javascript">

$(function(){




});

$(function(){

	$(".btn-file").click(function(){

		$("input[type='file']").click();

	});



	$(".recharge-footer-box label").click(function(){

		if($(this).hasClass("cur")){

			$(this).removeClass("cur");

		}else{

			$(this).addClass("cur");

		}

	});



	$(".recharge-btn").click(function(){

		if($("#shop_name").val() == ''){

			return layer.open({content:"请输入商家名称",skin:'msg',time:3});
		}

		if($("#shop_tel").val() == ''){
			return layer.open({content:"请输入商家电话",skin:'msg',time:3});
		}

		if($("#shop_add").val() == ''){
			return layer.open({content:"请输入商家地址",skin:'msg',time:3});
		}

		if($("#shop_contacts").val() == ''){
			return layer.open({content:"请输入联系人",skin:'msg',time:3});
		}

		if($("#shop_yyzz").val() == ''){
			return layer.open({content:"请上传营业执照",skin:'msg',time:3});
		}

		if($("#shop_move").val() == ''){
			return layer.open({content:"请输入手机号",skin:'msg',time:3});
		}

		if($("#shop_wx").val() == ''){
			return layer.open({content:"请输入微信",skin:'msg',time:3});
		}

		if(!$(".recharge-footer-box label").hasClass("cur")){
			return layer.open({content:"请同意服务条款及隐私协议",skin:'msg',time:3});
		}
		var shop_name = $("#shop_name").val();
		var shop_tel = $("#shop_tel").val();
		var shop_add = $("#shop_add").val();
		var shop_contacts = $("#shop_contacts").val();
		var shop_yyzz = $("#shop_yyzz").val();
		var shop_move = $("#shop_move").val();
		var shop_wx = $("#shop_wx").val();
		$.ajax({
			url : "recharge_info.php",
			type: "post",
			data:{"shop_name":shop_name,"shop_tel":shop_tel,"shop_add":shop_add,"shop_contacts":shop_contacts,"shop_yyzz":shop_yyzz,"shop_move":shop_move,"shop_wx":shop_wx,},
			dataType:'JSON',
			success:function(data){
				console.log(data);
				if(data.status == 'y'){
					WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						{
							"appId" : '<?php echo $SignParam['appId']; ?>',
							"timeStamp" : '<?php echo $SignParam['timeStamp']; ?>',
							"nonceStr" : '<?php echo $SignParam['nonceStr']; ?>',
							"package" : '<?php echo $SignParam['package']; ?>',
							"signType" : '<?php echo $SignParam['signType']; ?>',
							"paySign" : '<?php echo $SignParam['paySign']; ?>',
						},

						function(ret){
							if(ret.err_msg == "get_brand_wcpay_request:cancel"){
								layer.open({content:"您已取消了此次支付",skin:'msg',time:3});
							}else if(ret.err_msg == "get_brand_wcpay_request:fail"){
								layer.open({content:"支付失败，请重新尝试",skin:'msg',time:3});
							}else if(ret.err_msg == "get_brand_wcpay_request:ok"){
								layer.open({content:"支付成功,等待审核",skin:'msg',time:3});
								location.href = 'member.php';//跳转支付成功页面
							}else{
								layer.open({content:"未知错误"+ret.err_msg,skin:'msg',time:3});
							}
						}
					);
				}else{
					return layer.open({content:data.info,skin:'msg',time:3});
				}
			}
		})




	});

});



</script>

</body>

</html>
